<template>
    <el-dialog v-dialogDrag :title="!dataForm.pkInform ? '新增' : '修改'" :close-on-click-modal="false"
        :before-close="closeDailog" :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="120px">
            <ec-form-item-header value="投诉信息"></ec-form-item-header>
            <el-row :gutter="15">
                <el-col :span="12">
                    <el-form-item label="被举报店铺ID" prop="pkShop">
                        <el-input v-model="dataForm.pkShop" placeholder="被举报店铺ID" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="被举报商品ID" prop="pkGood">
                        <el-input v-model="dataForm.pkGood" placeholder="被举报商品ID" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15">
                <el-col :span="12">
                    <el-form-item label="举报类型" prop="informType">
                        <el-input v-model="dataForm.informType" placeholder="举报类型" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="举报状态" prop="informStatus">
                        <el-input v-model="dataForm.informStatus" placeholder="举报状态" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15">
                <el-col :span="12">
                    <el-form-item label="举报内容" prop="informContent">
                        <el-input v-model="dataForm.informContent" placeholder="举报内容" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="图片路径" prop="informAnnex">
                        <el-input v-model="dataForm.informAnnex" placeholder="图片路径" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="15">
                <el-col :span="12">
                    <el-form-item label="举报时间" prop="informTime">
                        <el-input v-model="dataForm.informTime" placeholder="举报时间" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="举报人ID" prop="informTargetId">
                        <el-input v-model="dataForm.informTargetId" placeholder="举报人ID" maxlength="30" show-word-limit>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <ec-form-item-header value="回应信息"></ec-form-item-header>
            <el-form-item label="回应内容" prop="respondContent">
                <el-input v-model="dataForm.respondContent" type="textarea" :autosize="{ minRows: 3, maxRows: 10}"
                    placeholder="回应内容" maxlength="300" show-word-limit>
                </el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="closeDailog()">取消</el-button>
            <el-button type="primary" :loading="submitLoading" @click="dataFormSubmit()">确定</el-button>
        </span>
    </el-dialog>
</template>

<script>
    import * as shopinformService from '@/api/mall/shopinform'

    export default {
        data() {
            return {
                visible: false,
                submitLoading: false,
                dataForm: {
                    pkInform: 0,
                    informTargetId: '',
                    pkGood: '',
                    pkShop: '',
                    informType: '',
                    informContent: '',
                    informAnnex: '',
                    informTime: '',
                    informStatus: '',
                    respondContent: '',
                    revision: '',
                },
                dataRule: {
                    informTargetId: [{
                        required: true,
                        message: '举报人ID不能为空',
                        trigger: 'blur'
                    }],
                    pkGood: [{
                        required: true,
                        message: '被举报商品ID不能为空',
                        trigger: 'blur'
                    }],
                    pkShop: [{
                        required: true,
                        message: '被举报店铺ID不能为空',
                        trigger: 'blur'
                    }],
                    informType: [{
                        required: true,
                        message: '举报类型不能为空',
                        trigger: 'blur'
                    }],
                    informContent: [{
                        required: true,
                        message: '举报内容不能为空',
                        trigger: 'blur'
                    }],
                    informAnnex: [{
                        required: true,
                        message: '图片路径不能为空',
                        trigger: 'blur'
                    }],
                    informTime: [{
                        required: true,
                        message: '举报时间不能为空',
                        trigger: 'blur'
                    }],
                    informStatus: [{
                        required: true,
                        message: '举报状态不能为空',
                        trigger: 'blur'
                    }],
                    respondContent: [{
                        required: true,
                        message: '回应内容不能为空',
                        trigger: 'blur'
                    }],
                    revision: [{
                        required: true,
                        message: '乐观锁不能为空',
                        trigger: 'blur'
                    }],
                }
            }
        },
        methods: {
            init(id) {
                this.dataForm.pkInform = id || 0
                this.visible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].resetFields()
                    if (this.dataForm.pkInform) {
                        shopinformService.getShopInformInfo(this.dataForm.pkInform).then(data => {
                            this.dataForm.informTargetId = data.informTargetId
                            this.dataForm.pkGood = data.pkGood
                            this.dataForm.pkShop = data.pkShop
                            this.dataForm.informType = data.informType
                            this.dataForm.informContent = data.informContent
                            this.dataForm.informAnnex = data.informAnnex
                            this.dataForm.informTime = data.informTime
                            this.dataForm.informStatus = data.informStatus
                            this.dataForm.respondContent = data.respondContent
                            this.dataForm.revision = data.revision
                            this.dataForm.createdBy = data.createdBy
                            this.dataForm.createdTime = data.createdTime
                            this.dataForm.updatedBy = data.updatedBy
                            this.dataForm.updatedTime = data.updatedTime
                            this.dataForm.deleFlag = data.deleFlag
                        })
                    }
                })
            },
            // 表单提交
            dataFormSubmit() {
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {
                        this.submitLoading = true
                        var params = {
                            'pkInform': this.dataForm.pkInform || undefined,
                            'informTargetId': this.dataForm.informTargetId,
                            'pkGood': this.dataForm.pkGood,
                            'pkShop': this.dataForm.pkShop,
                            'informType': this.dataForm.informType,
                            'informContent': this.dataForm.informContent,
                            'informAnnex': this.dataForm.informAnnex,
                            'informTime': this.dataForm.informTime,
                            'informStatus': this.dataForm.informStatus,
                            'respondContent': this.dataForm.respondContent,
                            'revision': this.dataForm.revision,
                            'createdBy': this.dataForm.createdBy,
                            'createdTime': this.dataForm.createdTime,
                            'updatedBy': this.dataForm.updatedBy,
                            'updatedTime': this.dataForm.updatedTime,
                            'deleFlag': this.dataForm.deleFlag
                        }
                        var tick = !this.dataForm.pkInform ? shopinformService.addShopInform(params) :
                            shopinformService.updateShopInform(params)
                        tick.then(data => {
                            this.$message({
                                message: '操作成功',
                                type: 'success',
                                duration: 1500,
                                onClose: () => {
                                    this.submitLoading = false
                                    this.visible = false
                                    this.$emit('refreshDataList')
                                }
                            })
                        }).catch((res) => {
                            this.submitLoading = false
                            this.closeDailog()
                        })
                    }
                })
            },
            closeDailog() {
                this.$refs['dataForm'].resetFields()
                this.visible = false
            }
        }
    }
</script>